import QS from "qs"
import axios from "axios"       //引入axios

// import 
import { Loading } from 'element-ui';       //引入Loading
// let loadingInstance = Loading.service(options);
// 添加axios的默认属性，请求超时时间
let loadingInstance = null
axios.defaults.timeout = 5000
// 4、设置基础地址
// axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1/"
axios.defaults.baseURL = "http://123.56.105.243:8080"
// 获取token 
let token = localStorage.getItem("token")
console.log("token", token);

//5axios拦截器
// ①请求拦截器
axios.interceptors.request.use((config) => {
  console.log(config)
  // 设置请求头
  config.headers["token"] = token
  console.log('configgggg', config);
  if (config.method == 'get') {
    QS.stringify(config.params)
  }
  loadingInstance = Loading.service({
    text: "Loading",
    spinner: "el-icon-loading",
  });
  return config
})
// 2.响应拦截
axios.interceptors.response.use(res => {
  console.log(res);
  loadingInstance.close()
  return res
})
// 页面抛出axios
export default axios